#!/bin/bash

###################################################################################
# 控制台颜色
BLACK="\033[1;30m"
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
PURPLE="\033[1;35m"
CYAN="\033[1;36m"
RESET="$(tput sgr0)"
###################################################################################
printf "${BLUE}\n"
cat << EOF
###########################################################################
       ____   _       U  ___ u   _   _   ____           _
    U /"___| |"|       \/"_ \/U |"|u| | |  _"\      U  /"\  u     ___
    \| | u U | | u     | | | | \| |\| |/| | | |      \/ _ \/     |_"_|
     | |/__ \| |/__.-,_| |_| |  | |_| |U| |_| |\     / ___ \      | |
      \____| |_____|\_)-\___/  <<\___/  |____/ u    /_/   \_\   U/| |\u
     _// \\  //  \\      \\   (__) )(    |||_        \\    >>.-,_|___|_,-.
    (__)(__)(_")("_)    (__)      (__)  (__)_)      (__)  (__)\_)-' '-(_/

#   @system: suit for CentOS7+
#   @author: Xiao XX
#
###########################################################################
EOF



printf "${RESET}\n"

printf "${GREEN}##############################################################${RESET}\n"

printf "${YELLOW}This is assistant for Deploying backend on CentOS${RESET}\n"

printf "${RED}this just for inner use,please !!!${RESET}\n"

printf "${BLUE}select one item for you want to do !!!${RESET}\n"

printf "${GREEN}###############################################################${RESET}\n"



PS3="Please select one item in
    [1] update yum-repo
    [2] config network
    [3] install jdk
    [4] install mysql8
    [5] install nginx
    [6] install tomcat8
    [7] install redis
    [8] install pgsql
    [9] Quit
    Input a Num:"
options=("update yum-repo" "config network" "install jdk" "install mysql8" "install nginx" "install tomcat8" "install redis" "install pgsql" "Quit")

select choice in "${options[@]}"; do
  case $choice in
    "update yum-repo")
      read -p " Are you confirm update yum-repo?[yes/no]: " confirm
      if [ "$confirm" == "yes" ] || [ "$confirm" == "y" ]; then
        EOF
        printf "${RESET}"
        printf "${GREEN}>>>>>>>> start update yum-repo.${RESET}\n"
        curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
        printf "${GREEN}>>>>>>>> update yum-repo done.${RESET}\n"
      else
        echo "Return to previous step"
      fi
      ;;
    "config network")
      read -p " Are you confirm config-network?[yes/no]: " confirm
      if [ "$confirm" == "yes" ] || [ "$confirm" == "y" ]; then
        EOF
        printf "${RESET}"
        printf "${GREEN}>>>>>>>> start config network.${RESET}\n"
        output=$(command ./config-network.sh)
        printf "${GREEN}>>>>>>>> ${output}.${RESET}\n"
        printf "${GREEN}>>>>>>>> config network done.${RESET}\n"
      else
        echo "Return to previous step"
      fi
      ;;
    "install jdk")
      read -p " Are you confirm install jdk8 ?[yes/no]: " confirm
      if [ "$confirm" == "yes" ] || [ "$confirm" == "y" ]; then
        EOF
        printf "${RESET}"
        printf "${GREEN}>>>>>>>> start install jdk8.${RESET}\n"
        ./jdk8-install.sh
        printf "${GREEN}>>>>>>>> install jdk8 done.${RESET}\n"
      else
        printf ${YELLOW}"Return to previous step.${RESET}\n"
      fi
      ;;
    "install mysql8")
      read -p " Are you confirm install mysql8 ?[yes/no]: " confirm
        if [ "$confirm" == "yes" ] || [ "$confirm" == "y" ]; then
          EOF
          printf "${RESET}"
          printf "${GREEN}>>>>>>>> start install mysql8.${RESET}\n"
          ./mysql8-install.sh
          printf "${GREEN}>>>>>>>> install mysql8 done.${RESET}\n"
        else
          printf ${YELLOW}"Return to previous step.${RESET}\n"
        fi
      ;;
    "install nginx")
      read -p " Are you confirm install nginx ?[yes/no]: " confirm
        if [ "$confirm" == "yes" ] || [ "$confirm" == "y" ]; then
          EOF
          printf "${RESET}"
          printf "${GREEN}>>>>>>>> start install nginx.${RESET}\n"
          ./nginx-install.sh
          printf "${GREEN}>>>>>>>> install nginx done.${RESET}\n"
        else
          printf ${YELLOW}"Return to previous step.${RESET}\n"
        fi
      ;;
    "install tomcat8")
      read -p " Are you confirm install tomcat8 ?[yes/no]: " confirm
        if [ "$confirm" == "yes" ] || [ "$confirm" == "y" ]; then
          EOF
          printf "${RESET}"
          printf "${GREEN}>>>>>>>> start install tomcat8.${RESET}\n"
          ./tomcat8-install.sh
          printf "${GREEN}>>>>>>>> install tomcat8 done.${RESET}\n"
        else
          printf ${YELLOW}"Return to previous step.${RESET}\n"
        fi
      ;;
    "install redis")
      read -p " Are you confirm install redis ?[yes/no]: " confirm
        if [ "$confirm" == "yes" ] || [ "$confirm" == "y" ]; then
          EOF
          printf "${RESET}"
          printf "${GREEN}>>>>>>>> start install redis.${RESET}\n"
          ./redis-install.sh
          printf "${GREEN}>>>>>>>> install redis done.${RESET}\n"
        else
          printf ${YELLOW}"Return to previous step.${RESET}\n"
        fi
      ;;
    "install pgsql")
      read -p " Are you confirm install pgsql ?[yes/no]: " confirm
        if [ "$confirm" == "yes" ] || [ "$confirm" == "y" ]; then
          EOF
          printf "${RESET}"
          printf "${GREEN}>>>>>>>> start install pgsql.${RESET}\n"
          ./postgresql-install.sh
          printf "${GREEN}>>>>>>>> install pgsql done.${RESET}\n"
        else
          printf ${YELLOW}"Return to previous step.${RESET}\n"
        fi
      ;;
    "Quit")
      printf ${YELLOW}"This Just A Start,We Will Back!.${RESET}\n"
      break
      ;;
    *)
      printf ${YELLOW}"Invalid Item,Will Quite.${RESET}\n"
      break
      ;;
  esac
done
